//
//  ViewController.m
//  teaching
//
//  Created by 衣尚品1 on 15/4/28.
//  Copyright (c) 2015年 衣尚品1. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *bigScrollView;

@property (weak, nonatomic) IBOutlet UIButton *teacherButton;
@property (weak, nonatomic) IBOutlet UIButton *studentButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //隐藏两个按钮
    self.teacherButton.hidden = YES;
    self.studentButton.hidden = YES;
    
    //scrollView设代理
    self.bigScrollView.delegate = self;
    
    //创建照片数组
    NSArray *arr = [[NSArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png", nil];
    
    //创建imageview放进scrollview
    for (int i = 0 ; i < arr.count ; i++) {
        
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:arr[i]];
        
        imageView.frame = CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
        
        //添加到第二层，不然会挡着button
        [self.bigScrollView insertSubview:imageView atIndex:1];
    }
    
    //设置scrollview滑动宽度
    self.bigScrollView.contentSize = CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height);
    //隐藏滚动杆
    self.bigScrollView.showsHorizontalScrollIndicator = NO;
    //强制分页
    self.bigScrollView.pagingEnabled = YES;
    //关闭滑动弹簧效果
    self.bigScrollView.bounces = NO;
    

}

#pragma mark - 每次滑动scrollview都会调用的方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    //获取水平方向的滚动距离
    CGFloat offsetX = scrollView.contentOffset.x;
    //求页码
    double pageDouble = offsetX/scrollView.frame.size.width;
    //四舍五入
    int pageInt = (int)(pageDouble + 0.5);
    
    if (pageInt == 3) {
        self.teacherButton.hidden = NO;
        self.studentButton.hidden = NO;
    }
    else {
        self.teacherButton.hidden = YES;
        self.studentButton.hidden = YES;
    }
    
}


- (IBAction)clickTeacher:(id)sender {
    NSLog(@"I'm teacher!");
}
- (IBAction)clickStudent:(id)sender {
    NSLog(@"I'm student!");
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
